const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const TimeFixPlugin = require('time-fix-plugin');

var publicPath = '/__jest__';


module.exports = {
    mode: 'development',
    devtool: 'eval-source-map',
    context: path.resolve(__dirname, '..'),
    entry: {
        bundle: [
            './test/html.jest.js',
        ]
    },
    output: {
        path: path.resolve(__dirname, '../dist' + publicPath),
        filename: '[name].js',
        chunkFilename: 'chunk.[name].js',
        publicPath: publicPath + "/"
    },
    module: {
        rules: [{
            test: /\.(js|jsx)$/,
            exclude: /node_modules/,
            loader: 'babel-loader',
            query: {
                "presets": ["@babel/preset-env"],
                "plugins": [[
                    "@babel/plugin-transform-runtime",
                    {
                        "helpers": false,
                        "regenerator": true
                    }
                ],
                    "@babel/plugin-transform-async-to-generator",
                ]
            }
        }, {
            test: /\.json$/,
            type: 'javascript/auto',
            use: [require.resolve('json-loader')]
        }, {
            test: /\.html$/,
            loader: 'html-loader?minimize=false'
        },{
            test: /\.css$/,
            use: ['style-loader', 'css-loader']
        }
        ]
    },
    resolve: {
        extensions: ['.js', '.jsx', '.json', '.scss', '.less', '.css'],
        alias: {
            'cess-core': path.join(__dirname, '../src'),
        }
    },
    plugins: [
        new webpack.NamedModulesPlugin(),
        new TimeFixPlugin(),
        new webpack.NoEmitOnErrorsPlugin(),
        new webpack.DefinePlugin({'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)}),
        new HtmlWebpackPlugin({
            filename: path.resolve(__dirname, './../dist/' + publicPath + '/index.html'),
            template: 'test/index.html',
        }),
    ]
};
